#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@NAME		:main.py
@TIME		:2021/08/21 23:02:12
@AUTHOR     :watalo
@VERSION	:0.0.x
'''

import os
from openpyxl import Workbook, load_workbook

try:
    wb_s = load_workbook('./performance/input/data_source.xlsx')
    wb = load_workbook('./performance/output/source.xlsx')
    print(wb.active.max_row)
except FileNotFoundError:
    if os.path.exists('./performance/output/source.xlsx') == False:
        wb = Workbook() 
        ws = wb.active
        ws.title = '贷款'
        ws1 = wb.create_sheet('存款')
        ws2 = wb.create_sheet('有价值户')
        ws3 = wb.create_sheet('高价值户')
        title_list = ['日期','一级机构','二级机构','员工ID','员工姓名',
                    '1一般性贷款时点余额','1比年初','1比月初','1比上日',
                    '1_1对公贷款时点余额余额','1_1比年初','1_1比月初','1_1比上日',
                    '1_2零售贷款时点余额','1_2比年初','1_2比月初','1_2比上日',	
                    '2一般性贷款日均情况余额','2比年初','2比月初','2比上日',
                    '2_1对公贷款日均余额','2_1比年初','2_1比月初','2_1比上日',	
                    '2_2零售贷款日均余额','2_2比年初','2_2比月初','2_2比上日']
        title_list1 = ['日期','一级机构','二级机构','员工ID','员工姓名',
                    '1一般性存款时点余额','1比年初','1比月初','1比上日',
                    '1_1对公存款时点余额余额','1_1比年初','1_1比月初','1_1比上日',
                    '1_2零售存款时点余额','1_2比年初','1_2比月初','1_2比上日',	
                    '2一般性存款日均情况余额','2比年初','2比月初','2比上日',
                    '2_1对公存款日均余额','2_1比年初','2_1比月初','2_1比上日',	
                    '2_2零售存款日均余额','2_2比年初','2_2比月初','2_2比上日']
        title_list2 = ['日期',]
        title_list3 = ['日期',]
        for i in enumerate(title_list):
            cells = ws.cell(row=1,column=i[0]+1,value=i[1])
            print(cells.value)
        for i in enumerate(title_list1):
            cells = ws1.cell(row=1,column=i[0]+1,value=i[1])
            print(cells.value)
        for i in enumerate(title_list2):
            cells = ws2.cell(row=1,column=i[0]+1,value=i[1])
            print(cells.value)
        for i in enumerate(title_list3):
            cells = ws3.cell(row=1,column=i[0]+1,value=i[1])
            print(cells.value)

        wb.save('./performance/output/source.xlsx')
        wb = load_workbook('./performance/output/source.xlsx')
    else:
        '原始数据文件不存在'
finally:
    for title in wb_s.sheetnames:
        ws_s = wb_s[title]
        ws = wb[title]
        start_row = ws.max_row +1
        for i in range(ws_s.max_row - 1):
            for j in range(ws_s.max_column):
                try:
                    if j == 0 or j == 3:
                        ws.cell(start_row + i, column =j+1, value = ws_s.cell(i+2, j+2).value)
                    else:
                        ws.cell(start_row + i, column =j+1, value = ws_s.cell(i+2, j+2).value/10000)
                except:
                    ws.cell(start_row + i, column =j+1, value = ws_s.cell(i+2, j+2).value)


    wb.save('./performance/output/source.xlsx')

        


